package com.nhatth.contactsharer;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;


public class SelectedContactAdapter extends ArrayAdapter<Contact> {
	
//	Contact currentContact = null;
	public OnContactRemovedListener removedListener;
	
	public SelectedContactAdapter(Context context, int textViewResourceId) {
		super(context, textViewResourceId);
		// TODO Auto-generated constructor stub
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if(v == null){
			LayoutInflater li = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = li.inflate(R.layout.list_selected_contact, null);
		}
		TextView name = (TextView) v.findViewById(R.id.list_selected_name);
		Button btnDelete = (Button) v.findViewById(R.id.list_selected_btn_delete);
		Contact con = getItem(position);
//		currentContact = con;
		name.setText(con.name);
		btnDelete.setTag(con);
		btnDelete.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Contact con = (Contact) v.getTag();
				remove(con);
				removedListener.onRemove(con);
			}
		});
		return v;
	}
	
//	private void removeCurrentContact()
//	{
//		remove(currentContact);
//		removedListener.onRemove(currentContact);
//	}
	
	
}
